using System;

using OpenXmlWriter.Packaging;

namespace OpenXmlWriter.WordprocessingML.Packaging
{
	public class FooterPart : OpenXmlPart
	{
    private const string PartRelationshipType =
      "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer";

    private const string PartName = "footer";
    private const string PartPath = "word";
    private const string PartExtension = ".xml";
    public const string PartContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml";
    private string _targetPath;

    public override void Initialize(OpenXmlPackage openXmlPackage, OpenXmlPartContainer openXmlPartContainer)
    {
      base.Initialize(openXmlPackage, openXmlPartContainer);
      _targetPath = CreateUniquePath();

      _contentType = new ContentType(_targetPath, PartContentType, false);
    }

    private string CreateUniquePath()
    {
      return PartPath + "/" + PartName + FooterPartHelper.GetNextId() + PartExtension;
    }

    public override string RelationshipType
    {
      get
      {
        return PartRelationshipType;
      }
    }

    public override ContentType ContentType
    {
      get
      {
        return _contentType;
      }
    }

    public override void AddTo(OpenXmlPartCollection parts)
    {
      parts.Add(_targetPath, this);
    }

    public override string TargetPath
    {
      get
      {
        return _targetPath;
      }
    }	

    public ImagePart AddImagePart(string fileName, string contentType)
    {
      ImagePart part = (ImagePart) Activator.CreateInstance(typeof(ImagePart), true);
      part.Initialize(_openXmlPackage, _openXmlPartContainer, fileName, contentType);
      part.AddTo(_parts);
      Relationship relationship = new Relationship(TargetPath, part.TargetPath, part.RelationshipType);
      part.Relationship = relationship;
      _relationships.Add(relationship);
      return part;
    }
  }
}
